package cn.swh.guguanjia.controller;

import cn.swh.guguanjia.entity.Result;
import cn.swh.guguanjia.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Arrays;
import java.util.Map;

@RestController
@RequestMapping("/mapper/role")
public class SysRoleController {

    @Autowired
    SysRoleService service;

    @RequestMapping("")
    public ModelAndView toIndex() {
        return new ModelAndView("/role/role.html");
    }

    @RequestMapping("toUser")
    public ModelAndView toUser() {
        return new ModelAndView("/role/role-user.html");
    }

    @RequestMapping("toUpdate")
    public ModelAndView toUpdate() {
        return new ModelAndView("/role/role-save.html");
    }

    @RequestMapping("selectPage/{pageNum}/{pageSize}")

    public Result selectPage(@PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize, @RequestParam Map<String, Object> map) {
        return new Result(true, "移除成功", service.selectPage(pageNum, pageSize, map));
    }


    @RequestMapping("deleteBatch")
    public Result deleteBatch(long rid, long[] ids) {
        return new Result(service.deleteBatch(rid, ids));
    }

    @RequestMapping("insertBatch")
    public Result insertBatch(long rid, Long[] cids) {
        return new Result(true, "添加成功", service.insertBatch(rid, Arrays.asList(cids)));
    }

    @RequestMapping(value = "update", method = RequestMethod.POST)
    public Result update(@RequestBody Map<String, Object> map) {
        return new Result(true,"更新成功",service.updateByPrimaryKeySelective(map));
    }
}
